styleproperty: Move member variables
authorBenjamin Otte <otte@redhat.com>
Sat, 31 Dec 2011 18:59:16 +0000 (19:59 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:53 +0000 (18:37 +0100)
These variables are only relevant for style properties, but not for
shorthands, so put them there.

gtk/gtkcssstyleproperty.c
gtk/gtkcssstylepropertyprivate.h
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index 8e2013781a4fffdc873447bcf395c86bcb3c2259..66ce7ff020a5c971dc3fd95fd0e7f64f28db312a 100644 (file)
@@ -27,6 +27,8 @@
 enum {
   PROP_0,
   PROP_ID,
+  PROP_INHERIT,
+  PROP_INITIAL
 };
 
 G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY)
@@ -43,6 +45,32 @@ gtk_css_style_property_constructed (GObject *object)
   G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object);
 }
 
+static void
+gtk_css_style_property_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
+{
+  GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
+  const GValue *initial;
+
+  switch (prop_id)
+    {
+    case PROP_INHERIT:
+      property->inherit = g_value_get_boolean (value);
+      break;
+    case PROP_INITIAL:
+      initial = g_value_get_boxed (value);
+      g_assert (initial);
+      g_value_init (&property->initial_value, G_VALUE_TYPE (initial));
+      g_value_copy (initial, &property->initial_value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static void
 gtk_css_style_property_get_property (GObject    *object,
                                      guint       prop_id,
@@ -56,6 +84,12 @@ gtk_css_style_property_get_property (GObject    *object,
     case PROP_ID:
       g_value_set_boolean (value, property->id);
       break;
+    case PROP_INHERIT:
+      g_value_set_boolean (value, property->inherit);
+      break;
+    case PROP_INITIAL:
+      g_value_set_boxed (value, &property->initial_value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -68,6 +102,7 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->constructed = gtk_css_style_property_constructed;
+  object_class->set_property = gtk_css_style_property_set_property;
   object_class->get_property = gtk_css_style_property_get_property;
 
   g_object_class_install_property (object_class,
@@ -77,6 +112,20 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
                                                       P_("The numeric id for quick access"),
                                                       0, G_MAXUINT, 0,
                                                       G_PARAM_READABLE));
+  g_object_class_install_property (object_class,
+                                   PROP_INHERIT,
+                                   g_param_spec_boolean ("inherit",
+                                                         P_("Inherit"),
+                                                         P_("Set if the value is inherited by default"),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class,
+                                   PROP_INITIAL,
+                                   g_param_spec_boxed ("initial-value",
+                                                       P_("Initial value"),
+                                                       P_("The initial specified value used for this property"),
+                                                       G_TYPE_VALUE,
+                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   klass->style_properties = g_ptr_array_new ();
 }
@@ -125,6 +174,24 @@ _gtk_css_style_property_lookup_by_id (guint id)
   return g_ptr_array_index (klass->style_properties, id);
 }
 
+/**
+ * _gtk_css_style_property_is_inherit:
+ * @property: the property
+ *
+ * Queries if the given @property is inherited. See
+ * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance>
+ * the CSS documentation</ulink> for an explanation of this concept.
+ *
+ * Returns: %TRUE if the property is inherited by default.
+ **/
+gboolean
+_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
+{
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
+
+  return property->inherit;
+}
+
 /**
  * _gtk_css_style_property_get_id:
  * @property: the property
@@ -142,19 +209,21 @@ _gtk_css_style_property_get_id (GtkCssStyleProperty *property)
   return property->id;
 }
 
-gboolean
-_gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
-{
-  g_return_val_if_fail (property != NULL, FALSE);
-
-  return GTK_STYLE_PROPERTY (property)->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
-}
-
+/**
+ * _gtk_css_style_property_get_initial_value:
+ * @property: the property
+ *
+ * Queries the initial value of the given @property. See
+ * <ulink url="http://www.w3.org/TR/css3-cascade/#intial>
+ * the CSS documentation</ulink> for an explanation of this concept.
+ *
+ * Returns: a reference to the initial value. The value will never change.
+ **/
 const GValue *
 _gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
 {
-  g_return_val_if_fail (property != NULL, NULL);
+  g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
 
-  return &GTK_STYLE_PROPERTY (property)->initial_value;
+  return &property->initial_value;
 }
 
index 0436f98ae21a9d2de01f7558fe4983ea73c9d356..32ab48dfdda314f23345864653045c9a63d3e2be 100644 (file)
@@ -39,7 +39,9 @@ struct _GtkCssStyleProperty
 {
   GtkStyleProperty parent;
 
+  GValue initial_value;
   guint id;
+  guint inherit :1;
 };
 
 struct _GtkCssStylePropertyClass
index 63badd9951723c72d562c6f8a8381fa253f693c7..3543952fa9e069cade0ced1765b5d491bb3d8dab 100644 (file)
@@ -1801,7 +1801,7 @@ _gtk_style_property_default_value (GtkStyleProperty   *property,
                                    GtkStateFlags       state,
                                    GValue             *value)
 {
-  g_value_copy (&property->initial_value, value);
+  g_value_copy (_gtk_css_style_property_get_initial_value (GTK_CSS_STYLE_PROPERTY (property)), value);
 }
 
 static gboolean
@@ -2495,41 +2495,42 @@ _gtk_style_property_register (GParamSpec               *pspec,
                               const GValue *            initial_value)
 {
   GtkStyleProperty *node;
+  GValue initial_fallback = { 0, };
 
-  node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
-                       "name", pspec->name,
-                       "value-type", pspec->value_type,
-                       NULL);
-  node->flags = flags;
-  node->pspec = pspec;
-  node->property_parse_func = property_parse_func;
-  node->parse_func = parse_func;
-  node->print_func = print_func;
-
-  /* initialize the initial value */
-  if (initial_value)
-    {
-      g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
-      g_value_copy (initial_value, &node->initial_value);
-    }
-  else
+  if (initial_value == NULL)
     {
-      g_value_init (&node->initial_value, pspec->value_type);
+      g_value_init (&initial_fallback, pspec->value_type);
       if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
-        g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
+        g_value_set_object (&initial_fallback, gtk_theming_engine_load (NULL));
       else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
-        g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
+        g_value_take_boxed (&initial_fallback, pango_font_description_from_string ("Sans 10"));
       else if (pspec->value_type == GDK_TYPE_RGBA)
         {
           GdkRGBA color;
           gdk_rgba_parse (&color, "pink");
-          g_value_set_boxed (&node->initial_value, &color);
+          g_value_set_boxed (&initial_fallback, &color);
         }
       else if (pspec->value_type == GTK_TYPE_BORDER)
         {
-          g_value_take_boxed (&node->initial_value, gtk_border_new ());
+          g_value_take_boxed (&initial_fallback, gtk_border_new ());
         }
       else
-        g_param_value_set_default (pspec, &node->initial_value);
+        g_param_value_set_default (pspec, &initial_fallback);
+
+      initial_value = &initial_fallback;
     }
+
+  node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
+                       "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE,
+                       "initial-value", initial_value,
+                       "name", pspec->name,
+                       "value-type", pspec->value_type,
+                       NULL);
+  node->pspec = pspec;
+  node->property_parse_func = property_parse_func;
+  node->parse_func = parse_func;
+  node->print_func = print_func;
+
+  if (G_IS_VALUE (&initial_fallback))
+    g_value_unset (&initial_fallback);
 }
index d498c4c6d84ba886d97628f62f11b6f6c627d117..c907451d7ecef33a71181b7804990026b5d9494f 100644 (file)
@@ -61,8 +61,6 @@ struct _GtkStyleProperty
   GType value_type;
 
   GParamSpec               *pspec;
-  GtkStylePropertyFlags     flags;
-  GValue                    initial_value;
 
   GtkStylePropertyParser    property_parse_func;
   GtkStyleUnpackFunc        unpack_func;